package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TrainingPlan;
import com.ruoyi.system.service.ITrainingPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训Controller
 * 
 * @author fyt
 * @date 2025-03-03
 */
@RestController
@RequestMapping("/system/educate")
public class TrainingPlanController extends BaseController
{
    @Autowired
    private ITrainingPlanService trainingPlanService;

    /**
     * 查询培训列表
     */
    @PreAuthorize("@ss.hasPermi('system:educate:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingPlan trainingPlan)
    {
        startPage();
        List<TrainingPlan> list = trainingPlanService.selectTrainingPlanList(trainingPlan);
        return getDataTable(list);
    }

    /**
     * 导出培训列表
     */
    @PreAuthorize("@ss.hasPermi('system:educate:export')")
    @Log(title = "培训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingPlan trainingPlan)
    {
        List<TrainingPlan> list = trainingPlanService.selectTrainingPlanList(trainingPlan);
        ExcelUtil<TrainingPlan> util = new ExcelUtil<TrainingPlan>(TrainingPlan.class);
        util.exportExcel(response, list, "培训数据");
    }

    /**
     * 获取培训详细信息
     */
        @PreAuthorize("@ss.hasPermi('system:educate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(trainingPlanService.selectTrainingPlanById(id));
    }

    /**
     * 新增培训
     */
    @PreAuthorize("@ss.hasPermi('system:educate:add')")
    @Log(title = "培训", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingPlan trainingPlan)
    {
        return toAjax(trainingPlanService.insertTrainingPlan(trainingPlan));
    }

    /**
     * 修改培训
     */
    @PreAuthorize("@ss.hasPermi('system:educate:edit')")
    @Log(title = "培训", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingPlan trainingPlan)
    {
        return toAjax(trainingPlanService.updateTrainingPlan(trainingPlan));
    }

    /**
     * 删除培训
     */
    @PreAuthorize("@ss.hasPermi('system:educate:remove')")
    @Log(title = "培训", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trainingPlanService.deleteTrainingPlanByIds(ids));
    }

    /**
     * 获取培训信息
     * @param id
     * @return
     */
    @RequestMapping("/getTrainingPlanById/{id}")
    public AjaxResult getTrainingPlanById(@PathVariable Long id) {

        return AjaxResult.success(trainingPlanService.selectTrainingPlanAddRedisById(id));
    }
    @RequestMapping("/getMessage")
    public AjaxResult getMessage() {
        String message = "审核成功";
        System.out.println("接口调用成功3");
        return AjaxResult.success("审核成功");
    }
}
